package server.controller.recordController;

import server.db.DBFactory;
import server.model.factory.ModelFactory;
import server.util.InfoUtils.Info;
import server.util.InfoUtils.InfoEnum;
import server.util.InfoUtils.InfoUtil;
import server.util.MyUtils;
import server.util.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

//获取购买记录
@WebServlet("/getRecordOfStore")
public class GetRecordByDateServlet extends HttpServlet {
    private static final long serialVersionUID = -7036622086097024159L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Info info = null;
        String startDate = req.getParameter("start");
        String endDate = req.getParameter("end");
        Integer storeId = ModelFactory.getStoreModel().getStoreId(req);
        if (!MyUtils.NOTNULL(startDate, endDate, storeId)) {
            info = InfoUtil.getInfo(InfoEnum.PARAMS_NULL);
        } else {
            info = ModelFactory.getRecordModel().getRecordByDate(storeId, startDate, endDate);
        }
        ResponseUtil.responseMessage(resp, info,2);
    }
}